<table border="1" cellspacing="0" class="table table-hover table-bordered table-condensed">
  <thead>
    <tr>
      <th class="bg-primary text-center" rowspan="2">地区</th>
      <th class="bg-primary text-center" rowspan="2">大区</th>
      <th class="bg-primary text-center" colspan="3">双月预算明细</th>
      <th class="bg-primary text-center" colspan="3">双月结算明细</th>
    </tr>
    <tr>
      <th class="bg-primary text-center">预算申请金额</th>
      <th class="bg-primary text-center">申请店数</th>
      <th class="bg-primary text-center">预算审核金额</th>
      <th class="bg-primary text-center">结算申请金额</th>
      <th class="bg-primary text-center">结算审核金额</th>
      <th class="bg-primary text-center">最终结算金额</th>
    </tr>
  </thead>
  <tbody>
    <?php
    $nowArea = '';//当前循环地区
    $nowRegion = '';//当前循环大区
    foreach($placeTree as $area => $regionList){
      foreach($regionList as $region => $spsareaList){
        //大区汇总
        $regionStoreIds = isset($regionToStoreList[$region]) ? array_keys($regionToStoreList[$region]) : array();
        $regionTotal = $this->carProcessModel->countTotalListByStoreIds($regionStoreIds, $procList);
    ?>
    <tr>
      <?php if($nowArea != $area){?>
        <td class="text-center" rowspan="<?php echo getArrayDeepCount($regionList,1,1);?>">
          <?php if( in_array($this->user['userRole'], array(3,4,5,6))){?>
            <a href="<?=printUrl('Main','adminDetail',array('area'=>urlencode($area),'year'=>$year, 'timeUnit'=>$timeUnit,'fundType'=>$fundType))?>"><?=$area?></a>
          <?php }else{
            echo $area;
            }
          $nowArea = $area;
          ?>
        </td>
      <?php }?>
      <?php if($nowRegion != $region){?>
      <td class="text-center">
        <?php if( in_array($this->user['userRole'], array(3,4,5,6))){?>
          <a href="<?=printUrl('Main','adminDetail',array('area'=>urlencode($area),'region'=>urlencode($region),'year'=>$year, 'timeUnit'=>$timeUnit,'fundType'=>$fundType))?>"><?=$region;?></a>
        <?php }else{
          echo $region;
          }
          $nowRegion = $region;
        ?>
      </td>
      <?php }?>
      <td class="text-center"><?php echo $regionTotal['budgetApply'];?></td>
      <td class="text-center"><?php echo $regionTotal['storeCount'];?></td>
      <td class="text-center"><?php echo $regionTotal['budgetAudit'];?></td>
      <td class="text-center"><?php echo $regionTotal['settleApply'];?></td>
      <td class="text-center"><?php echo $regionTotal['settleAudit'];?></td>
      <td class="text-center"><?php echo $regionTotal['finalSettleMoney'];?></td>
    </tr>
    <?php
        }
        //地区汇总
        $areaStoreIds = isset($areaToStoreList[$area]) ? array_keys($areaToStoreList[$area]) : array();
        $areaTotal = $this->carProcessModel->countTotalListByStoreIds($areaStoreIds, $procList);
    ?>
      <tr>
        <td class="text-center">合计</td>
        <td class="text-center"><?php echo $areaTotal['budgetApply'];?></td>
        <td class="text-center"><?php echo $areaTotal['storeCount'];?></td>
        <td class="text-center"><?php echo $areaTotal['budgetAudit'];?></td>
        <td class="text-center"><?php echo $areaTotal['settleApply'];?></td>
        <td class="text-center"><?php echo $areaTotal['settleAudit'];?></td>
        <td class="text-center"><?php echo $areaTotal['finalSettleMoney'];?></td>
      </tr>
    <?php
    }
    ?>
    <?php
      //所有汇总
      $allTotal = getArrayColumnTotal($procList,array('budgetApply','budgetAudit','settleApply','settleAudit','finalSettleMoney'),1);
    ?>
      <tr>
        <td class="text-center" colspan="2"><a href="<?=printUrl('Main','adminDetail',array('year'=>$year, 'timeUnit'=>$timeUnit,'fundType'=>$fundType))?>">全国</a></td>
        <td class="text-center"><?php echo $allTotal['budgetApply'];?></td>
        <td class="text-center"><?php echo count($procList);?></td>
        <td class="text-center"><?php echo $allTotal['budgetAudit'];?></td>
        <td class="text-center"><?php echo $allTotal['settleApply'];?></td>
        <td class="text-center"><?php echo $allTotal['settleAudit'];?></td>
        <td class="text-center"><?php echo $allTotal['finalSettleMoney'];?></td>
      </tr>
  </tbody>
</table>